using OneDark.Update;
using SQLite;
using System.IO;

namespace OneDark.Sqlite
{
    public class Product
    {
        [AutoIncrement, PrimaryKey]
        public int Id { get; set; }

        public string Name { get; set; }
        public decimal Price { get; set; }

        public uint TotalSales { get; set; }
    }

    public class DbMgr
    {
        private static GITDB _db;

        //DbMgr()
        //{
        //    Setup();
        //    _db.CreateTable<GitProperty>();
        //}
        public static void Setup()
        {
            _db = new GITDB();
            var mapping = _db.GetMapping<GitProperty>();
            var info = _db.GetTableInfo("GitProperty");
            if (info.Count == 0)
            {
                _db.CreateTable<GitProperty>();
            }
        }

        public static void TearDown()
        {
            if (_db != null) _db.Close();
        }
    }

    public enum OrderLineStatus
    {
        Placed = 1,
        Shipped = 100
    }

    public class GITDB : SQLiteConnection
    {
        private const string strDbName = "GITDB.sqlite";

        public GITDB(bool storeDateTimeAsTicks = true, object key = null, bool wal = true) : base(new SQLiteConnectionString(strDbName, storeDateTimeAsTicks, key: key))
        {
            Trace = true;
            if (wal)
                EnableWriteAheadLogging();
        }

        public GITDB(SQLiteConnectionString connectionString, bool wal = true) : base(connectionString)
        {
            Trace = true;
            if (wal)
                EnableWriteAheadLogging();
        }

        public GITDB(string path, bool storeDateTimeAsTicks = true, object key = null, bool wal = true) : base(new SQLiteConnectionString(path, storeDateTimeAsTicks, key: key))
        {
            Trace = true;
            if (wal)
                EnableWriteAheadLogging();
        }
    }

    public class TestPath
    {
        public static string GetTempFileName()
        {
#if NETFX_CORE
			var name = Guid.NewGuid () + ".sqlite";
			return Path.Combine (Windows.Storage.ApplicationData.Current.LocalFolder.Path, name);
#else
            return Path.GetTempFileName();
#endif
        }
    }
}